import axios from "axios";

import store from "@/Store";

import { mapMutations } from "vuex";
const service = axios.create({
  baseURL: "http://121.89.205.189:3000/api/",
  timeout: 30000 * 1000,
});

let obj = {
  $store: store,
  ...mapMutations(["showLoading", "hideLoading"]),
 
};
// 请求拦截器
service.interceptors.request.use((config) => {
  obj.showLoading();
  if (sessionStorage.getItem("token")) {
    config.headers.token = sessionStorage.getItem("token");
  }
  return config;
});

// 响应拦截器
service.interceptors.response.use((res) => {
  obj.hideLoading();
  return res;
});
export default service;
